<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<title>封条管理及验证系统--新增/修改账户信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/comm.jsp"%>
	<style type="text/css">
	<!--
	fieldset {
	    padding:10px;
	    margin:10px;
	    width:270px;
	    color:#333; 
	} 
	legend {
	    color:#06c;
	    font-weight:600; 
	} 
	-->
	</style>
</head>
<script>
	function initPage(){
	  var selcountry=document.getElementById("userInfo.country").value;   		
   	  if(selcountry=="HK"||selcountry=="CN"||selcountry=="TW"){
   	  	//中国或香港,显示手机、中文名等
   	  	document.getElementById("tr_zhname").style.display="block";
   	  	if(selcountry=="CN")
   	  	  document.getElementById("tr_mobile").style.display="block";
   	  	else
   	  	  document.getElementById("tr_mobile").style.display="none";
   	  }else{
   	  	document.getElementById("tr_zhname").style.display="none";
   	  	document.getElementById("tr_mobile").style.display="none";
   	  }
	}
	
	var checkflag=true;//判断是否可用
	var checkEmailflag=true;//判断邮箱是否可用
	function checkUserId(txtUserId){
		var userIdVal=txtUserId.value;
		if(userIdVal == ""){
			$d("userIdError").innerHTML="请输入账户代码";
			return;		
		}
		userIdVal=$('#hdfCompanyId').val()+"-"+userIdVal;
		var params = {
					userIdVal:userIdVal
					};
		$.ajax({type: "POST",
		       url: "ajaxUser_checkUserId.do",
		       data: params,
		       async: true,
		       success: function(result){
				 if(result.userIdExist=="false"){
				  	userIdError.innerHTML="用户名可用";
				 	checkflag=true;
				 }else{
				  	userIdError.innerHTML="用户名已存在";
				  	checkflag=false;
				 }
			  }
			},"json");
	}
	
	function checkEmail(txtEmail){
		var emailStr=txtEmail.value;
		if(emailStr == ""){
			$d("emailError").innerHTML="请输入Email";
			return;		
		}
		var userIdVal=$d("hdfUserId").value;
		var params = {
					userIdVal:userIdVal,
					email:emailStr
					};
		$.ajax({type: "POST",
		       url: "ajaxPwd_checkEmailExist.do",
		       data: params,
		       async: true,
		       success: function(result){
				 if(result.retcode=='0000'){
				  	emailError.innerHTML="";
				  	checkEmailflag=true;
				 }else{
				  	emailError.innerHTML=result.retmsg;
				 	checkEmailflag=false;
				 }
			  }
			},"json");
	}
	
	function checkSubmit(){
		if(checkflag==false){
			alert("用户名已存在");
			return false;
		}
		
		if(checkEmailflag==false){
			alert("Email已被占用");
			return false;
		}
		
		return true;
	}
</script>
<body leftmargin="0" topmargin="0" marginheight="0" onload="initPage();">
  <s:form name="formpage" action="userInfo_save.do" namespace="/ajax">
  	<s:token>
	</s:token>
	<div align="center">
	<s:hidden id="hdfId" name="userInfo.id" value="%{#request.userInfo.id}" />
	<s:hidden id="hdfUserId" value="%{#request.userInfo.userId}" />
	<s:hidden id="hdfCompanyId" name="userInfo.companyId" value="%{#request.userInfo.companyId}" />
	<s:hidden name="userInfo.country" value="%{#request.userInfo.country}" />
	<s:hidden id="hdfFlag" name="flag" value="%{#request.selfFlag}" />
  	<%@ include file="/messages.jsp"%>
				<table align="center" width="650">
					<tr>
						<td align="right" width="120">
							账户代码：
						</td>
						<td>
							<s:if test="userInfo.id == null ">
								<input id="userId" name="userInfo.userId" type="text" value="${userInfo.userId }"
							 		maxlength="20" size="15" onblur="checkUserId(this);"/>
							 	<span id="userIdError"></span>
							 </s:if>
							 <s:else>
							 	${userInfo.userId }
							 </s:else>
						</td>
					</tr>
					
					<tr id="tr_zhname">
						<td align="right">
							中文姓名：
						</td>
						<td>
							<input name="userInfo.chineseName" type="text" value="${userInfo.chineseName }"
								maxlength="40" size="20" class="required" title="*必填" />
						</td>
					</tr>

					<tr>
						<td align="right">
							英文姓名：
						</td>
						<td>
							<input name="userInfo.firstName" type="text" maxlength="20" size="10"
								value="${userInfo.firstName }" title="first name"/>
							<input name="userInfo.lastName" type="text" maxlength="20" size="10"
								value="${userInfo.lastName }" title="last name"/>
						</td>
					</tr>
					
					<tr>
						<td align="right">
							性别：
						</td>
						<td>
							<s:radio name="userInfo.sex" list="#{'1':'男','0':'女','2':'保密'}" value="%{#request.userInfo.sex}"></s:radio> 							
						</td>
					</tr>
					
					<!-- 不能修改自己的部门,级别,状态 -->
					<s:if test="#request.selfFlag == false">
					<tr>
						<td align="right" width="120">
							所属部门：
						</td>
						<td>
							<s:select name="userInfo.deptId" list="#request.deptList"
							 headerKey="-1" headerValue="请选择" 
							 value="#request.userInfo.deptId"
							>
							</s:select>
						</td>
					</tr>
					<tr>
						<td align="right" width="120">
							账户级别：
						</td>
						<td>
							<s:select name="userInfo.userRole" list="#request.roleList"
							 headerKey="-1" headerValue="请选择"	></s:select>
						</td>
					</tr>
					<s:if test="#request.userInfo.id != null ">
					<tr>
						<td align="right" width="120">
							状态：
						</td>
						<td>
							<s:radio name="userInfo.status" list='#{"1":"正常","2":"冻结"}' value="#request.userInfo.status"></s:radio>
						</td>
					</tr>
					</s:if>
					</s:if>
					
					<tr id="tr_mobile">
						<td align="right">
							手机：
						</td>
						<td>
							<input name="userInfo.cellphone" type="text" maxlength="40"
								 value="${userInfo.cellphone }"  />
						</td>
					</tr>

					<tr>
						<td align="right">
							固定电话：
						</td>
						<td>
							<input name="userInfo.countryCode" type="text" maxlength="10" size="5"
								value="${userInfo.countryCode }" />
							<input name="userInfo.regionCode" type="text" maxlength="10" size="5"
								value="${userInfo.regionCode }" />
							<input name="userInfo.telephone" type="text" maxlength="20" size="15"
								value="${userInfo.telephone }" />
						</td>
					</tr>
					
					<tr>
						<td align="right" width="120">
							Email地址：
						</td>
						<td>
							<input name="userInfo.email" type="text" value="${userInfo.email }"
							 maxlength="50" size="30" onblur="checkEmail(this);"/>
							 <span id="emailError"></span>
						</td>
					</tr>
					
					<tr>
						<td align="right" width="120">
							邮件语言：
						</td>
						<td>
							<s:select list="#{'en':'英文','zh_CN':'中文','NO NEED':'不接收'}"	 
							 name="userInfo.lang"
					  		 value="#request.userInfo.lang" 
					  		 id="lang"
					  		 cssStyle="width:80px" >
							</s:select>
						</td>
					</tr>

					<s:if test="#request.userInfo.id == null ">
						<tr>
							<td align="right">
								登录密码：
							</td>
							<td>
								<input name="userInfo.password" id="password1" type="password"
									size="20" maxlength="20" class="required" value="" title="*必填" />
							</td>
						</tr>

						<tr>
							<td align="right">
								再次输入密码：
							</td>
							<td>
								<input name="password2" id="password2" type="password" size="20"
									maxlength="20" class="required" value="" title="*必填" />
							</td>
						</tr>
					</s:if>

					<tr>
						<td colspan="2" align="center">
							<input type="submit" class="button" id="ok" name="ok"
								value=" 保 存 " onclick="return checkSubmit();"/>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="button" class="button" id="resets" value=" 返 回 " onclick="javascript:history.go(-1)"/>
						</td>
					</tr>
				</table>
			</div>
		</s:form>
  </body>
</html>